/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleship_server;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 *
 * @author jalejandrovc
 */
public class PlayerController {

    SocketConnection socketConnection;

    public PlayerController(SocketConnection sc) {
        socketConnection = sc;
    }

    public String validateLogin(String username, String password) {
        if (!ServerGameController.getInstance().database.validateLogin(username, password)) {
            return "Invalid credentials.";
        } else if (ServerGameController.getInstance().lookForPlayer(username)) {
            return "The user is already online.";
        } else {
            return "true";
        }
    }

    public boolean validateLoginAdmin(String username, String password) {
        return (ServerGameController.getInstance().database.validateLoginAdmin(username, password) && !ServerGameController.getInstance().lookForPlayer(username));
    }

    public Player login(String username, String lastIPAddress) {
        return (ServerGameController.getInstance().database.login(username, lastIPAddress));
    }

    public boolean addPlayer(String name, String username, String password, String mail, String lastIPAddress) throws SQLIntegrityConstraintViolationException {
        return (ServerGameController.getInstance().database.addPlayer(name, username, password, mail, lastIPAddress));
    }
}
